<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1. 注册提交数据到登录页
    // 2. 在登录页进行数据解析

    // "http://127.0.0.1:5500/day13/html/login.html?user=a123123&pwd=123123&phone=17386141516&email=1272071496%40qq.com"

    // 参数数据"?user=a123123&pwd=123123&phone=17386141516&email=1272071496%40qq.com"
    // (1) 单条数据以键值对的形式存在(key=value  key描述 value值)
    // (2) 数据之间以 & 分隔

    // 数据解析: 将数据解析为对象 => {user:"xxx",pwd:"xxx"}

    var search = location.search;  // ?user=a123123&pwd=123123&phone=17386141555&email=123123123%40qq.com
    console.log(search);

    var data = {};
    if (search) {  // 有数据在解析
        var str = search.substring(1); // 从下标为1的位置向后截取
        console.log(str);
        var list = str.split("&");
        console.log(list);  // ['user=a123123', 'pwd=123123', 'phone=17386141555', 'email=123123123%40qq.com'

        for (var i = 0; i < list.length; i++) {
            var item = list[i];  // 每一条数据 'user=a123123'
            var key = item.split("=")[0]; // "user"
            var val = item.split("=")[1]; // "a123123"
            console.log(item, key, val);

            // data[key] = val;
            data[key] = decodeURIComponent(val); // 对键值进行解码

        }


    } else { // 没有数据
        location.href = "./register.html"; // 跳转注册页
    }


    console.log(data);

</script>

</html>